﻿// IIFE
// Immediately Invoked Function Envocation

// App that allows us to manage out Contacts
var name = "Will"; // on global scope

//alert("loaded!");

//var myContacts = (function () { // on global

    var name = "Gil"; // on local scope
    function getName() {
        return name;
    }


    // Contacts Constructor 
    var Contact = function (fName, lName, city) {
        this.fName = fName,
        this.lName = lName,
        this.city = city
    }
    // Add a property to prototype 
    Contact.prototype = { age: 19 };

// add a Property & Method
    var hobbies = {
        game: "Pacman",
        sayDetails: function () {
            console.log(this.fName + " likes: " + this.game);
        }
    }
    Contact.prototype = hobbies;


// Add prototype to the Array Object
    Array.prototype.peanutButter = function (slot) {
        console.log(this[slot].sayDetails());
        // c1.sayDetails();
    }

    function greeting() {
        var finNum = 0;
        for (var i = 0; i < arguments.length; i++) {
            console.log(arguments[i]);
            finNum += arguments[i];
        }
        console.log(finNum);

    }

    




/*
// loop until condition is met
    while (hasNose) {
        //
    }
// loop on all properties (unknown amount)
    for (var i in o) {

    }
// loop over a specific amount
    for (var i = 0; i < length; i++) {

    }
    */





    // Create a few 'Contacts'
    var c1 = new Contact("Anna", "Cassaro", "LouisVille");
    var c2 = new Contact("Bill", "Knapp", "HTizzle");
    var c3 = new Contact("Joshoua", "Lerma", "Corpus Christi");

    // Array of Contacts - house all of our data
    var ContactArr = []; // empty
    function getContacts() {
        return ContactArr;
    }

    // Add contacts to array
    ContactArr.push(c1, c2, c3);

    console.log("THESE ARE THE CONTACTS: ", ContactArr);
    var strHolder = ""; // hold the hmtl...
    strHolder += "<ul>";// <table></table>
    for (var i = 0; i < ContactArr.length; i++) {
        strHolder += "<li>"+ ContactArr[i].fName + " " + ContactArr[i].lName + " from: " + ContactArr[i].city + "</li>"
    }
    strHolder += "</ul>";

    // Render the string to the Div
    $("#myResults").html(strHolder);


    // User Events
    $("#AddContact").click(function () {
        alert("Hello from button");
    });



// Expose Variables & Metohds
    /*
    return {
        getName: getName,
        getContacts: getContacts
    }
    */

//})();